<template>
  <div class="todo-add">
    <input
      type="text"
      name="todo"
      v-model="todoContent"
      @keyup.enter="emitAddTodo"
    />
    <button @click="emitAddTodo">
      <i class="plus"></i>
    </button>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
const emit = defineEmits(["addTodo"]);
const todoContent = ref();

function emitAddTodo() {
  if (todoContent.value.trim()) {
    emit("addTodo", todoContent.value);
    todoContent.value = "";
  }
}
</script>


<style>
.todo-add {
  position: relative;
  display: flex;
  align-items: center;
}

.todo-add input {
  padding: 16px 52px 16px 18px;
  border-radius: 48px;
  border: none;
  outline: none;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.15);
  width: 100%;
  font-size: 16px;
  color: #626262;
}

.todo-add button {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(#c0a5f3, #7f95f7);
  border: none;
  outline: none;

  color: white;
  position: absolute;
  right: 0;
  cursor: pointer;
}

.todo-add .plus {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(white, white), linear-gradient(white, white);
  /* 横一条 竖一条 */
  background-size: 50% 2px, 2px 50%;
  background-position: center;
  background-repeat: no-repeat;
}
</style>
